/*
 *  Copyright 2008 Mark Ashworth <javameme@gmail.com>.
 *
 *  Licensed under the GNU General Public License v3 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.gnu.org/licenses/gpl-3.0.html
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package xperiment.metaphor.model.contact;

import xperiment.metaphor.model.*;
import java.io.Serializable;

/**
 * Contact Information
 *
 * @author Mark Ashworth
 * @version 1.0.0
 * @since 1.0.0
 */
public class ContactInformation extends AbstractBean implements Serializable {
    private static final long serialVersionUID = 1L;

    /* Telephone information */
    private String telephoneNo;
    private String cellphoneNo;
    private String facsimileNo;

    /* Email information */
    private String email;

    /** Address information */
    private Address postalAddress;
    private Address physicalAddress;


    public Address getPostalAddress() {
        return postalAddress;
    }

    public void setPostalAddress(Address address) {
        Address old = this.getPostalAddress();
        this.postalAddress = address;
        firePropertyChange("postalAddress", old, getPostalAddress());
    }

    public Address getPhysicalAddress() {
        return physicalAddress;
    }

    public void setPhysicalAddress(Address address) {
        Address old = getPhysicalAddress();
        this.physicalAddress = address;
        firePropertyChange("physicalAddress", old, getPhysicalAddress());
    }

    public String getCellphoneNo() {
        return cellphoneNo;
    }

    public void setCellphoneNo(String cellphoneNo) {
        String old = getCellphoneNo();
        this.cellphoneNo = cellphoneNo;
        firePropertyChange("cellphoneNo", old, getCellphoneNo());
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        String old = getEmail();
        this.email = email;
        firePropertyChange("email", old, getEmail());
    }

    public String getFacsimileNo() {
        return facsimileNo;
    }

    public void setFacsimileNo(String facsimileNo) {
        String old = getFacsimileNo();
        this.facsimileNo = facsimileNo;
        firePropertyChange("facsimileNo", old, getFacsimileNo());
    }

    public String getTelephoneNo() {
        return telephoneNo;
    }

    public void setTelephoneNo(String telephoneNo) {
        String old = getTelephoneNo();
        this.telephoneNo = telephoneNo;
        firePropertyChange("telephoneNo", old, getTelephoneNo());
    }

    /**
     * @return String 
     */
    public String toXML() {
        return toXML("address");
    }
    
    /**
     * 
     * @param nodeName The name of the contact information node
     * @return String
     */
    public String toXML(String nodeName) {
        
        return "<" + nodeName + " class='"+ getClass().getName() 
                + "' telephone-no='" + getTelephoneNo()
                + "' cellphone-no='" + getCellphoneNo()
                + "' facsimile-no='" + getFacsimileNo()
                + "' email='" + getEmail()
                + "' >"
                + (getPostalAddress() != null ? getPostalAddress().toXML("postal-address") : "")
                + (getPhysicalAddress() != null ? getPhysicalAddress().toXML("physical-address") : "")
                + "</" + nodeName + ">"
                ;
    }
}
